﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using IDal;

namespace Dal
{
    public class DbSessionFactory:IDbSessionFactory
    {
        /// <summary>
        /// 此方法的作用： 提高效率，在线程中 共用一个 DBSession 对象！
        /// </summary>
        /// <returns></returns>
        public IDbSession GetDbSession()
        {
            //从当前线程中 获取 DBContext 数据仓储 对象
            IDbSession dbSesion = CallContext.GetData(typeof(DbSessionFactory).Name) as DbSession;
            if (dbSesion == null)
            {
                dbSesion = new DbSession();
                CallContext.SetData(typeof(DbSessionFactory).Name, dbSesion);
            }
            return dbSesion;
        }
    }
}
